﻿using System;
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Smart_Archives.Entity;
using Smart_Archives.Models;
using Smart_Archives.Utils;

namespace Smart_Archives.Controllers
{
    public class HomeController : Controller
    {
        private readonly SaContext _saContext;

        public HomeController(SaContext saContext)
        {
            _saContext = saContext;
        }

        public IActionResult Index()
        {
            var model = new User
            {
                Username = "admin",
                Password = Md5Util.Md5Hash(Md5Util.Md5Hash("000000")),
                Realname = "admin",
                Status = 1
            };
            model.CreateTime = model.UpdateTime = DateTime.Now;
            _saContext.User.Add(model);
            _saContext.SaveChanges();
            return Content(model.Id.ToString());
        }

        public ViewResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }

    }
}
